import request from "./request";
// import APPVUE from '../APP';
import App from "../App";
var util = require("./util.js");
// request.config.baseURL = util.getApiUrl(8080);
function fail(res) {
	console.log(res);
  if (res.status == 401 && uni.getStorageSync("token")) {
    uni.setStorage({
      key: "token",
      data: false,
    });
    uni.showToast({
      title: "登录已过期，请重新登录!",
      duration: 2000,
      icon: "none",
    });
    setTimeout(() => {
      uni.reLaunch({
        url: "login",
      });
    }, 2000);
  } else {
    uni.showToast({
      title: "网络不太给力，请稍后再试！",
      duration: 2000,
      icon: "none",
    });
    // uni.showModal({
    // 	title: '提示',
    // 	content: '网络错误或服务器异常，请稍后再试！',
    // 	showCancel:false,
    // 	success: function(res) {
    // 		if (res.confirm) {
    // 			console.log('用户点击确定');
    // 		} else if (res.cancel) {
    // 			console.log('用户点击取消');
    // 		}
    // 	}
    // });
  }

  return res;
}
function success(res) {
  if (res.code == 700) {
    uni.showToast({
      title: "登录已过期，请重新登录!",
      duration: 2000,
      icon: "none",
    });
    uni.setStorage({
      key: "token",
      data: "",
    });
    setTimeout(() => {
      uni.reLaunch({
        url: "login",
      });
    }, 2000);
  } else if (res.code) {
    uni.showToast({
      title: res.message,
      duration: 2000,
      icon: "none",
    });
  }
  //    else if(res.resMsg=="签名校验失败！"){
  // 	uni.setStorage({
  // 		key: 'token',
  // 		data: false
  // 	});
  // 	uni.showToast({
  // 		"title": '登录已过期，请重新登录!',
  // 		"duration": 2000,
  // 		"icon": "none"
  // 	});
  // 	setTimeout(()=>{
  // 		uni.reLaunch({
  // 			url: '../pages/login'
  // 		});
  // 	},2000)
  // }
  return res;
}

const api = {
  //登陆
  login: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/guns/gunsApi/auth",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查最新的版本
  selectLatestVersion: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/app/version/selectLatestVersion.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //修改密码
  changePwd: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/guns/gunsApi/changePwd",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //获取权限
  appMenu: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/guns/gunsApi/appMenu",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //获取设备类型
  selectDictOptions: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/commons/selectDictOptions.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //获取设备信息
  selectAsset: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/stock/selectAsset.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询详情
  selectSbtz: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/scdd/sbtz/selectSbtz.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //有用水量得水厂
  selectRelation: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/scdd/sbtz/selectRelation.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //水厂用量
  getFSKUsed: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/scdd/sbtz/getFSKUsed.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询巡检单
  selectXjgd: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/xjgd/selectXjgd.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //完成巡检单的某个任务
  updateGdRw: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/updateGdRw.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查用户拥有的角色
  selectUserRoles: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/commons/selectUserRoles.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查设备
  selectSbTree: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/scdd/sbtz/selectSbTree.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //添加一个工单
  insertSCCJ: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/xjgd/insertSCCJ.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //开始工单
  updateStartXjgd: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/xjgd/updateStartXjgd.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //结束工单
  updateEndXjgd: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/xjgd/updateEndXjgd.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //添加巡检工单的一个轨迹
  insertGdgj: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/insertGdgj.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询巡检轨迹
  selectGdgj: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/selectGdgj.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询故障等级
  selectDictOptionsList: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/commons/selectDictOptionsList.do",
        method: "post",
      })
      .then(success)
      .catch(fail),
  //添加故障
  insertGz: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/insertGz.do",
        method: "post",
      })
      .then(success)
      .catch(fail),
  //查询故障列表
  selectGz: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/selectGz.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询故障列表
  updateBatchSuccessXjgdRw: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/xjgd/updateBatchSuccessXjgdRw.do",
        method: "post",
      })
      .then(success)
      .catch(fail),
  //查询预案
  selectYjya: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/Yjya/selectYjya.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询部门
  selectOrgOptionsList: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/commons/selectOrgOptionsList.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //添加应急事件
  insertYjsj: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/yjsj/insertYjsj.do",
        method: "post",
      })
      .then(success)
      .catch(fail),
  //查询应急事件
  selectYjsj: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/yjsj/selectYjsj.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询型号列表
  selectOnlineEquModel: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/scdd/sbtz/selectOnlineEquModel.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询负责人
  selectUserOptionsList: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/commons/selectUserOptionsList.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询维修记录
  selectJxjlDtl: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/jxjlDtl/selectJxjlDtl.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询故障记录
  selectGz: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/xjgl/selectGz.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
	  //可选用户
	  selectUserOptions: (body) =>
	    request
	      ({
	        body,
	        baseURL: util.getApiUrl(),
	        url: "/panzhihua/jsp/commons/selectUserOptions.do",
	        method: "get",
	      })
	      .then(success)
	      .catch(fail),
	  
	  getBiCurrentTotalNum: (body) =>
	    request({
	        body,
	        baseURL: util.getApiUrl(),
	        url: "/panzhihua/api/bi/getBiCurrentTotalNum.do",
	        method: "get",
	      })
	      .then(success)
	      .catch(fail),
	  selectFSKSSQSL: (body) =>
	    request({
	        body,
	        baseURL: util.getApiUrl(),
	        url: "/panzhihua/api/bi/selectFSKSSQSL.do",
	        method: "get",
	      })
	      .then(success)
	      .catch(fail),
	  selectLineYL: (body) =>
	    request({
	        body,
	        baseURL: util.getApiUrl(),
	        url: "/panzhihua/api/bi/selectLineYL.do",
	        method: "get",
	      })
	      .then(success)
	      .catch(fail),
  //查询派车单
  selectClglPcgl: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "/panzhihua/jsp/zhgl/selectClglPcgl.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //查询车辆
  selectClgl: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "panzhihua/jsp/zhgl/selectClgl.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
  //提交派车单
  insertClglPcgl: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "panzhihua/jsp/zhgl/insertClglPcgl.do",
        method: "post",
      })
      .then(success)
      .catch(fail),
  //审批派车单
  updateClglPcgl: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "panzhihua/jsp/zhgl/updateClglPcgl.do",
        method: "post",
      })
      .then(success)
      .catch(fail), 
  //查询架空管道数据
  getQzy: (body) =>
    request({
        body,
        baseURL: util.getApiUrl(),
        url: "panzhihua/api/wy/select_qzy_current_vlaue.do",
        method: "get",
      })
      .then(success)
      .catch(fail),
};
export default api;
